{% extends 'authuser/base.html' %}
{% load static %}
{% load jsonify %}

{% block page_content %}
<script src="{{ js_config.js_lib.authuser }}"></script>

<style type="text/css" media="screen" id="test">
	.warn{
		color: red;
	}
</style>
<script type="text/javascript">
//	eventBus=new Vue()

	username='{{ username }}'
	uid='{{ uid }}'

	heads=[
		{name:'old_pswd',editor:'password',label:'原密码',required:true}, //,help_text:'如果您是超级管理员，不需要输入原密码'},
		{name:'first_pswd',editor:'password',label:'新密码',required:true,fv_rule:'新密码:'},
		{name:'second_pswd',editor:'password',label:'确认输入',fv_rule:'match(first_pswd)'},
		{name:'validate_code',editor:'com-field-auth-validate-code',label:'验证码',required:true,show:'scope.row.validate_img'}
	]
	row={
		uid:uid,
		old_pswd:'',
		first_pswd:'',
		second_pswd:'',
		validate_img:null,
		username:username,
	}
	$(function(){
		new Vue({
			el:'#there',
			data:{
				heads:heads,
				row:row,
				errors:{},
				username:username,
			},
			mixins:[mix_fields_data,mix_nice_validator],
			methods:{
//				setError:function(errors){
//					ex.each(this.heads,function(head){
//						delete head.error
//					})
//					for(var k in errors){
//						var head = ex.findone(this.heads,{name:k})
//						Vue.set(head,'error',errors[k])
////						head.error=errors[k]
//					}
//				},
				save:function(){
					var self=this
					var post_data=[{fun:'changepswd',row:this.row}]
//					var url = ex.appendSearch('/d/ajax/authuser',self.search_args)
					cfg.show_load()
//					ex.post('/d/ajax/authuser',JSON.stringify(post_data),function (resp) {
//						callback(resp.changepswd)
					ex.director_call('authuser.changepswd',{row:this.row}).then(function (rt) {
						cfg.hide_load()
//						var rt = resp.changepswd
						if(rt.validate_img){
							Vue.set(self.row,'validate_img',rt.validate_img)
						}

						if(rt.errors){
							self.setErrors(rt.errors)
							self.showErrors(rt.errors)
						}else{
							cfg.toast('修改成功，跳转...')
							self.after_save(rt.row)
							self.setErrors({})
						}

					})
				},
				after_save:function(row){
					ex.vueSuper(this,{fun:'after_save',args:[row]})
					setTimeout(function(){
						location = '/'
					},2000)

				},
//				submit:function(){
//					var  self =this
//					var post_data=[{fun:'changepswd',row:this.row},]
//					$.post('/d/ajax/authuser',JSON.stringify(post_data),function(resp){
//						if(resp.changepswd.errors){
//							self.setError(resp.changepswd.errors)
//
//						}else if(resp.changepswd.status=='success'){
//							var search_args=ex.parseSearch()
//							if(search_args.next){
//								location=decodeURIComponent(search_args.next)
//							}else{
//								self.setError({})
//								alert('修改成功')
//							}
//							location = '/'
//						}
//
//					})
//				},
				cancel:function(){
					history.back()
				}
			}
		})
	})

</script>
<!--<div class="flex flex-jc">-->
	<!--<div class='flex-v' id="there">-->
		<div class="plain-panel" id="there">
			<h2 class='form-signin-heading' style="text-align: center;">修改您( <span v-text="username"></span> )的密码:</h2>
			<hr>
			<div style="max-width: 20em;margin: auto">
				<com-sim-fields  ref="panel"  :heads="heads" :row="row" ok-btn="修改" @submit="save"></com-sim-fields>
			</div>
			<!--class="msg-bottom"-->

			<!--<h2 class='form-signin-heading' style="text-align: center;">更改 <span v-text="username"></span> 密码</h2>-->
		</div>


		<!--<field v-for="head in heads" :name="head.name" :head="head" :row="row"></field>-->


	<!--<button class='btn btn-lg btn-primary btn-block' @click="save()">确定</button>-->
		<!--<div style="text-align: right;padding-top: 10px;">-->
			<!--<a href="javascript:;" @click="cancel()">取消</a>-->
		<!--</div>-->

	<!--</div>-->
<!--</div>-->

{% endblock %}